import {
  Controller,
  UsePipes,
  Body,
  Post,
  Put,
  Delete,
  Param,
  UseInterceptors,
  ClassSerializerInterceptor,
} from '@nestjs/common';
import ValidQuery from 'src/pipes/ValidQuery';
import { GetCalssifyDto, ConfigClassifyDto } from './dto';
import { PicClassifyService } from './pic-classify.service';
import { ApiTags, ApiOperation } from '@nestjs/swagger';

@ApiTags('图片分类')
@Controller('picClassify')
export class PicClassifyController {
  constructor(private readonly picClassifyService: PicClassifyService) {}
  @Post('getClassifyList')
  @UsePipes(ValidQuery)
  @UseInterceptors(ClassSerializerInterceptor)
  @ApiOperation({ description: '分页获取分类' })
  async getClassifyList(@Body() body: GetCalssifyDto) {
    try {
      const res = await this.picClassifyService.getClassifyList(body);
      return res;
    } catch (e) {
      console.log(`err: ${e}`);
      throw e;
    }
  }
  @Post('configClassify')
  @UsePipes(ValidQuery)
  @ApiOperation({ description: '配置分类' })
  async configClassify(@Body() body: ConfigClassifyDto) {
    try {
      const res = await this.picClassifyService.configClassify(body);
      return res;
    } catch (e) {
      console.log(`err: ${e}`);
      throw e;
    }
  }

  @Delete('delClassify/:id')
  @UsePipes(ValidQuery)
  @ApiOperation({ description: '删除分类' })
  async delClassify(@Param('id') id: number) {
    try {
      const res = await this.picClassifyService.delClassify(id);
      return res;
    } catch (e) {
      console.log(`err: ${e}`);
      throw e;
    }
  }
}
